package edu.ynu.se.xiecheng.achitectureclass.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@Where(clause = "is_deleted = 0")
@Table(name = "device")
public class DeviceEntity extends LogicEntity {


    @Column(nullable = false)
    private String deviceNo;

    @Column(nullable = false)
    private String deviceName;

    //0表示土壤设备，1表示空气检测设备，2表示摄像设备
    @Column(nullable = false)
    private Integer deviceClass;

    @Column
    private String deviceAddress;

    //单位
    @Column
    private String deviceUnit;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "greenhouse_id", nullable = false) //@JoinColumn 注解用于指定实体间关系的连接列。在这个例子中，它指定了数据库表中用于存储外键的列
    private GreenhouseEntity greenhouse;

    @OneToMany(mappedBy = "device", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JsonIgnoreProperties("device")
    private Set<SoilWaterDataEntity> soilWaterData;

    @OneToMany(mappedBy = "device", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JsonIgnoreProperties("device")
    private Set<SoilTemperatureDataEntity> soilTemperatureData;

    @OneToMany(mappedBy = "device", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JsonIgnoreProperties("device")
    private Set<SoilNDataEntity> soilNData;

    @OneToMany(mappedBy = "device", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JsonIgnoreProperties("device")
    private Set<AirTemperatureDataEntity> airTemperatureData;

    @OneToMany(mappedBy = "device", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JsonIgnoreProperties("device")
    private Set<CO2DataEntity> CO2Data;

    @OneToMany(mappedBy = "device", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JsonIgnoreProperties("device")
    private Set<CameraDataEntity> cameraData;
}
